/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "sle_connect_interface.h"
#include "kh_sle_connect.h"
#include "cmd_input.h"
#include <vector>
#include <memory>
#include <cstring>
#include <iterator>

namespace OHOS {
namespace NearLink {
namespace SleStandard {
namespace {
using namespace testing::ext;
} // namespace

class ConnectHandlerTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
};

void ConnectHandlerTest::SetUpTestCase() {}

void ConnectHandlerTest::TearDownTestCase() {}

void ConnectHandlerTest::SetUp() {
    SleErrorCode ret = InitSleConnectService();
    printf("ret = %d", ret);
}

void ConnectHandlerTest::TearDown() {}

HWTEST_F(ConnectHandlerTest, ConnectTest, TestSize.Level1)
{
    SleDeviceAddress remoteAddr = {
        .addrType = SLE_PUBLIC_ADDRESS_TYPE,
    };
    char addr[18];
    strcpy(addr, "00:11:aa:bb:f1:6b");
    if(strlen(addr) != 17) {
        printf("[SleConnectTestTool] SleSetHostAddress failed, invalid addr\r\n");
        return;
    }
    Str2Mac(remoteAddr.addr, addr);
    SleErrorCode ret = SleConnect(&remoteAddr);
    EXPECT_EQ(ret, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(ConnectHandlerTest, DisconnectTest, TestSize.Level1)
{
    SleDeviceAddress remoteAddr = {
        .addrType = SLE_PUBLIC_ADDRESS_TYPE,
    };
    char addr[18];
    strcpy(addr, "00:11:aa:bb:f1:6b");
    if(strlen(addr) != 17) {
        printf("[SleConnectTestTool] SleSetHostAddress failed, invalid addr\r\n");
        return;
    }
    Str2Mac(remoteAddr.addr, addr);
    SleErrorCode ret = SleDisconnect(&remoteAddr);
    EXPECT_EQ(ret, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(ConnectHandlerTest, UpdateConnParamTest, TestSize.Level1)
{
    SleConnectionParamUpdate param;
    param.connectId = 255;
    param.intervalMin = 255;
    param.intervalMax = 255;
    param.maxLatency = 255;
    param.supervisionTimeout = 10;
    SleErrorCode ret = SleUpdateConnParam(&param);
    EXPECT_EQ(ret, SLE_ERR_INVALID_PARAM);
}

HWTEST_F(ConnectHandlerTest, SendPairReqTest, TestSize.Level1)
{
    SleDeviceAddress remoteAddr = {
        .addrType = SLE_PUBLIC_ADDRESS_TYPE,
    };
    char addr[18];
    strcpy(addr, "00:11:aa:bb:f1:6b");
    if(strlen(addr) != 17) {
        printf("[SleConnectTestTool] SleSetHostAddress failed, invalid addr\r\n");
        return;
    }
    Str2Mac(remoteAddr.addr, addr);
    SleErrorCode ret = SendPairReq(&remoteAddr);
    EXPECT_EQ(ret, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(ConnectHandlerTest, RemovePairTest, TestSize.Level1)
{
    SleDeviceAddress remoteAddr = {
        .addrType = SLE_PUBLIC_ADDRESS_TYPE,
    };
    char addr[18];
    strcpy(addr, "00:11:aa:bb:f1:6b");
    if(strlen(addr) != 17) {
        printf("[SleConnectTestTool] SleSetHostAddress failed, invalid addr\r\n");
        return;
    }
    Str2Mac(remoteAddr.addr, addr);
    SleErrorCode ret = RemovePair(&remoteAddr);
    EXPECT_EQ(ret, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(ConnectHandlerTest, RemoveAllPairsTest, TestSize.Level1)
{
    SleErrorCode ret = RemoveAllPairs();
    EXPECT_EQ(ret, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(ConnectHandlerTest, GetDevicePairStateTest, TestSize.Level1)
{
    SleDeviceAddress remoteAddr = {
        .addrType = SLE_PUBLIC_ADDRESS_TYPE,
    };
    char addr[18];
    strcpy(addr, "00:11:aa:bb:f1:6b");
    Str2Mac(remoteAddr.addr, addr);
    SlePairState pairState;
    SleErrorCode ret = GetDevicePairState(&remoteAddr, &pairState);
    EXPECT_EQ(ret, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(ConnectHandlerTest, ReadRemoteRssiTest, TestSize.Level1)
{
    int8_t rssi;
    uint16_t connectId = 255;
    SleErrorCode ret = ReadRemoteRssi(connectId, &rssi);
    EXPECT_EQ(ret, SLE_ERR_INVALID_PARAM);
}

HWTEST_F(ConnectHandlerTest, GetConnectDevListTest, TestSize.Level1)
{
    SleConnectDev connectDevList[SLE_MAX_CONNECT_ID_NUM];
    uint16_t connectNum = SLE_MAX_CONNECT_ID_NUM;
    SleErrorCode ret = GetConnectDevList(connectDevList, &connectNum);
    EXPECT_EQ(ret, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(ConnectHandlerTest, GetConnectDeviceIdTest, TestSize.Level1)
{
    SleDeviceAddress remoteAddr = {
        .addrType = SLE_PUBLIC_ADDRESS_TYPE,
    };
    char addr[18];
    strcpy(addr, "00:11:aa:bb:f1:6b");
    Str2Mac(remoteAddr.addr, addr);
    uint16_t connectId = 255;
    SleErrorCode ret = GetConnectDeviceId(&remoteAddr, &connectId);
    EXPECT_EQ(ret, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(ConnectHandlerTest, CheckIsConnectedTest, TestSize.Level1)
{
    uint16_t connectId = 255;
    SleErrorCode ret = CheckIsConnected(connectId);
    EXPECT_EQ(ret, SLE_ERR_INVALID_PARAM);
}
}
} // namespace NetManagerStandard
} // namespace OHOS
